import React, { Component } from 'react';
import E from 'wangeditor';
import './style.scss';

class WangUEditor extends Component {
  componentDidMount() {
    const elem = this.ueditor;
    const editor = new E(elem);
    editor.customConfig.onchange = (html) => {
      this.props.wangEditorHtml(html);
      this.props.wangEditorJson(editor.txt.getJSON());
    };
    editor.customConfig.debug = true;
    // zindex设置防止菜单重合
    editor.customConfig.zIndex = 0;
    // 先监听在创建
    editor.create();
  }

  render() {
    return (
      <div ref={(ueditor) => { this.ueditor = ueditor; }} />
    );
  }
}

export default WangUEditor;
